% make_skp.m - generate a set of 'clean' .skp files for an experiment
% $Id: make_skp.m 320 2005-05-05 20:07:09Z odellj $
% $Log: make_skp.m,v $
% Revision 1.6  2004/07/14 20:33:24  odellj
% Updated to log make_skp messages.
%
% Revision 1.5  2004/07/14 19:58:33  odellj
% Updated for logging purposes.
%
% Revision 1.4  2004/07/01 18:06:48  edmaclin
% Fixed merged issues; ';' and/or fprintf statements
%
% Revision 1.3  2004/06/30 18:13:31  odellj
% Added more verbose fprintf statements.
%
% Revision 1.2  2004/05/21 19:02:03  edmaclin
% prints only "1s" digit in last (block ounter) line
%
% Revision 1.1.1.1  2004/02/18 20:09:49  odellj
% initial import into CVS
%
% Revision 1.2  2004/02/05 20:24:16  odellj
% Added Id and Log tags.
%

function make_skp(log_file)
global hdr

% Open the log file if it exists
%
if ~strcmp(log_file,'')
    logid = fopen(log_file,'a');
else logid = 1; end

for i_subj=1:size(hdr.subj_list,1)
    subj=sprintf('%03.0f', hdr.subj_list(i_subj));
    
    for i_SS = 1:size(hdr.SS,1)
        ss1 = deblank(hdr.SS(i_SS,:));
        skp_name = [hdr.data_path hdr.exp_name 'opt\' ss1 subj '.skp'];
        fid = fopen(skp_name,'r');
        if fid < 0    % if file doesn't exist (e.g. don't overwrite existing file)...
            fid = fopen(skp_name,'wt');    % open text file for writing
            fprintf(logid,'Writing file %s\r\n',skp_name);
            for i_config = 1:size(hdr.config,1)                
				for i_block = 1:hdr.n_blocks
                    fprintf(fid,' 1');
				end % Block
                fprintf(fid,'\n');
            end % config
            for i_block = 1:hdr.n_blocks  % print block # as last line to help manual editing
                fprintf(fid,'%2.0f',mod(i_block,10)); % print only "1s" digit
			end % Block
            fprintf(fid,'\n');
            fclose(fid);
            fprintf(logid,'%s written\r\n',skp_name);
        else
            fprintf(logid,'(status)  File %s already exists!\n',skp_name);
            fclose(fid);
        end
	end % SS
end % Subj                    

if logid ~= 1, fclose(logid); end


